import { userinfo } from '@/stores/counter'

export default function convertTime() {
  // const user = userinfo()
  // function getTime(timestamp:number) {
  //   const date = new Date(timestamp * 1000); // JavaScript 的 Date 对象接受毫秒数，所以要乘以1000
  //   const year = date.getFullYear();
  //   const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始计数，需要加1
  //   const day = String(date.getDate()).padStart(2, '0');
  //   // const hours = String(date.getHours()).padStart(2, '0');
  //   // const minutes = String(date.getMinutes()).padStart(2, '0');
  //   // const seconds = String(date.getSeconds()).padStart(2, '0');

  //   return `${year}-${month}-${day}`;
  //   // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  // }

  // return {
  //   getTime
  // }
  function getTime(timeArray: number[]) {
    const [year, month, day, hours, minutes, seconds] = timeArray;

    const formattedDate = new Date(year, month - 1, day, hours, minutes, seconds); // 月份是从0开始计数，需要减1
    const formattedYear = String(formattedDate.getFullYear());
    const formattedMonth = String(formattedDate.getMonth() + 1).padStart(2, '0');
    const formattedDay = String(formattedDate.getDate()).padStart(2, '0');
    const formattedHours = String(formattedDate.getHours()).padStart(2, '0');
    const formattedMinutes = String(formattedDate.getMinutes()).padStart(2, '0');
    const formattedSeconds = String(formattedDate.getSeconds()).padStart(2, '0');

    return `${formattedYear}-${formattedMonth}-${formattedDay} ${formattedHours}:${formattedMinutes}`;
  }

  return {
    getTime
  };
}